import pandas as pd
from pandas import DataFrame

datafile = './文本/货运量_1-1.csv' #第一行为属性标签

data = pd.DataFrame(pd.read_csv(datafile))
data2 = data.drop(['Year'],axis = 1) #删除Year列
data2 = data2.drop(['Airport name'],axis = 1) #删除Airport name列
data2 = data2.drop(['Airport coordinates'],axis = 1) #删除Airport coordinates列
a = data2.drop(['December'],axis = 1) #定义一个删除December列的DataFrame
a = a.drop(['Whole year'],axis = 1) #删除Whole year列
a['sum'] = a.apply(lambda x:x.sum(), axis = 1) #对1-11月求和
a = a['sum'].tolist() #转为列表
b = data2['Whole year'].tolist() 
c = data['December'].tolist() 
d = data['Whole year'].tolist()
for i in range(len(c)): 
    if c[i] != 0.0 and c[i] < b[i]: #若是12月不为0
        c[i] = b[i] - a[i]
    else: #若是12月为0
        c[i] = 0
        d[i] = a[i]
data['December'] = c
data['Whole year'] = d
data.to_csv(datafile,index = False,encoding = 'utf_8_sig') #重新导出